<template>
	<view class="container">
		<view class="separate">
			<view class="avator">
				<view class="con" @click="navTo('/pages/agent/user/info')">
					<image :src="userInfo.avatar" mode=""></image>
					<div class="zhanghao">
						<p style="font-weight: bold;">{{userInfo.nickname}}</p>
						<!-- <p>{{userInfo.mobile}}</p> -->
						<p>ID：{{userInfo.id}}</p>
					</div>
				</view>
			</view>
			
			<view class="separate-list">
				<view class="list_item" v-for="(item, index) in separateList" :key="index" @click="handleClick(item)">
					<view class="item_l">
						<image :src="item.icon" mode="widthFix"></image>
						<text>{{item.title}}</text>
					</view>
					<view class="item_r">
						<span v-if="item.type == 'tel'" style="color: #49A1FD;">400-989-8988</span>
						<image src="/static/img/agent/youce.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="loginoutbtn" @click="loginOut()">退出登录</view>
		</view>
	</view>
</template>

<script>
	import { settleRecord, getUserInfo } from '../../api/api.js'
	export default {
		data() {
			return {
				key: '',
				sum_money: '',
				userInfo: {},
				separateList:[
					{
						type:'account',
						title:'账号与安全',
						icon: require('../../static/img/account/zhanghao.png')
					},
					{
						type:'password',
						title:'修改密码',
						icon: require('../../static/img/account/mima.png')
					},
					{
						type:'bank',
						title:'绑定银行卡',
						icon: require('../../static/img/account/yinhang.png')
					},
					{
						type:'zfb',
						title:'绑定支付宝',
						icon: require('../../static/img/account/zhifubao.png')
					},
					{
						type:'tel',
						title:'客服电话',
						icon: require('../../static/img/account/kefu.png')
					}
				]
			}
		},
		onLoad() {
			// this.userInfo = uni.getStorageSync('user')
			// console.log(this.userInfo)
			// this.getList()
		},
		onShow() {
			this.getUser()
		},
		methods: {
			// 代理
			getList() {
				settleRecord().then(res => {
					console.log(res)
					this.sum_money = res.data.sum_money
					this.list = res.data.data
				})
			},
			getUser(){
				getUserInfo().then(res=>{
					console.log(res)
					this.userInfo = res.data
					uni.setStorageSync('user', res.data)
				})
			},
			toDetailed(id) {
				uni.navigateTo({
					url: '/pages/agent/user/detailed?id=' + id
				})
			},
			handleClick(item) {
				switch (item.type){
					case 'account':
						uni.navigateTo({
							url:'/pages/agent/user/userAccount'
						})
						break;
					case 'password':
						uni.navigateTo({
							url:'/pages/agent/user/editPassword?mobile=' + this.userInfo.mobile
						})
						break;
					case 'bank':
						uni.navigateTo({
							url:'/pages/agent/user/card'
						})
						break;
					case 'zfb':
						uni.navigateTo({
							url:'/pages/agent/user/band_zhifubao'
						})
						break;
					case 'tel':
						uni.makePhoneCall({
							phoneNumber: '400-989-8988'
						})
						break;
					default:
						break;
				}
			},
			loginOut(){
				uni.showModal({
					title: '提示',
					content: '确定退出登录吗？',
					showCancel: true,
					success: function(res) {
						if(res.confirm){
							uni.removeStorageSync("user");
							uni.removeStorageSync("token");
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}else if(res.cancel){
							console.log("===用户取消")
						}
						
					}
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		background-color: #f6f6f6;
	}

	.separate {
		width: 100%;
		height: 100%;
		.avator {
			width: 100%;
			height: 350upx;
			display: flex;
			// justify-content: center;
			align-items: center;
			// background-color: #8faeb3;
			background: url('../../static/img/agent/topbg.png') no-repeat center;
			background-size: 100% 100%;
			.con {
				display: flex;
				// flex-direction: column;
				align-items: center;
				margin-left: 15px;
				image {
					width: 120upx;
					height: 120upx;
					border-radius: 50%;
					margin-right: 20upx;
				}
				p{
					color: #FFFFFF;
					line-height: 26px;
				}
			}
		}

		.separate-list {
			width: 100%;
			margin-top: 20upx;
			.list_item {
				width: 100%;
				padding: 12px;
				margin: 20px auto;
				height: 90upx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #FFFFFF;
				.item_l {
					min-width: 100upx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					image {
						width: 24px;
						height: 24px;
						margin-right: 20upx;
					}
					text{
						font-size: 16px;
					}
				}

				.item_r {
					image {
						width: 12px;
						height: 12px;
					}
				}

			}
		}

	}
	
	.loginoutbtn{
		width: 80%;
		background: #FFFFFF;
		border-radius: 22px;
		font-weight: 500;
		font-size: 17px;
		color: #49A1FD;
		padding: 20rpx;
		margin: 80rpx auto;
		text-align: center;
	}
</style>
